Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace useDispatch with useQuery and request in FacilityCard, FacililyHome and FacilityUsers #6575

Merged
merged 21 commits into from
Nov 29, 2023

Conversation

sriharsh05
Copy link
Contributor

@sriharsh05 sriharsh05 commented Nov 9, 2023

WHAT

🤖 Generated by Copilot at ae5cd23

The pull request refactors the code for making and handling API calls in the Facility components to use the request utility and the useQuery hook. It also adds and modifies type definitions for the requests and the responses for various API endpoints in src/Redux/api.tsx and src/Components/Facility/models.tsx. The purpose of these changes is to improve the code readability, performance, and type safety.
The pull request partially refactors the codebase for managing facility module in the frontend. It replaces the redux actions and states with the custom request function and the useQuery hook for data fetching and updating. It improves the code quality, performance, and readability by removing unnecessary imports, variables, and dependencies.

This pull request makes the required changes to only 3 files and does not close the entire issue.

Proposed Changes

@coronasafe/care-fe-code-reviewers @coronasafe/code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

HOW

🤖 Generated by Copilot at ae5cd23

  • Refactor API calls to use request utility and useQuery hook for fetching and caching data from the API endpoints (F0,F1,F2)
  • Remove unused imports of useDispatch, statusType, useAbortableEffect, and action creators from ./src/Components/Facility/FacilityCard.tsx, ./src/Components/Facility/FacilityHome.tsx, and ./src/Components/Facility/FacilityUsers.tsx (link,link,link)
  • Add imports of request, routes, and useQuery from ./src/Redux/api.tsx to ./src/Components/Facility/FacilityCard.tsx, ./src/Components/Facility/FacilityHome.tsx, and ./src/Components/Facility/FacilityUsers.tsx (link,link,link)
  • Remove declarations of dispatch and dispatchAction from FacilityCard and FacilityHome components as they are no longer used for making API calls (link,link)
  • Modify handleNotifySubmit function in FacilityCard component to use request utility instead of dispatchAction function to send notification messages to the facility, using routes.sendNotificationMessages object to define the API endpoint and the types, and destructuring res and data from the response object (link)
  • Modify fetchData function in FacilityHome component to use useQuery hook instead of dispatch function to fetch the data for the facility, the capacity, the doctor, and the triage, using routes object to define the API endpoints and the types, and destructuring res, data, and refetch from the objects returned by the hook (link)
  • Move fetchData function inside the useEffect hook that runs when the permittedFacilityRes changes, instead of using the useAbortableEffect hook that runs when the fetchData function changes, and remove the useAbortableEffect hook as it is no longer needed (link)
  • Modify handleDeleteSubmit function in FacilityHome component to use request utility instead of dispatch function to delete the facility, using routes.deleteFacility object to define the API endpoint and the types, and passing id as a pathParams property to the request utility (link)
  • Modify handleUpdate function in FacilityHome component to use capacityFetch and doctorFetch functions instead of dispatch function to refetch the capacity and doctor data, using the functions returned by the useQuery hook that handles the fetching and caching of the data from the API endpoints (link,link,link,link)
  • Remove isLoading and setIsLoading from FacilityUsers component as they are no longer needed for handling the loading state of the data fetching (link)
  • Modify fetchFacilityName function in FacilityUsers component to use request utility instead of dispatch function to fetch the facility name and district id, using routes.getAnyFacility object to define the API endpoint and the types, and passing id as a pathParams property to the request utility (link)
  • Remove fetchData function from FacilityUsers component as it is no longer needed for fetching the facility users data, and use useQuery hook instead, using routes.getFacilityUsers object to define the API endpoint and the types, passing offset, limit, and facility_id as query and pathParams properties to the hook, setting prefetch property to facilityId !== undefined, and setting onResponse property to a function that updates the users and totalCount state variables with the data from the response (link)
  • Modify loadFacilities function in FacilityUsers component to use request utility instead of dispatch function to fetch the facilities for a given user, using routes.userListFacility object to define the API endpoint and the types, and passing username as a pathParams property to the request utility (link)
  • Modify handleUnlinkFacilitySubmit function in FacilityUsers component to use request utility instead of dispatch function to unlink a facility from a user, using routes.deleteUserFacility object to define the API endpoint and the types, and passing facility as a body and username as a pathParams property to the request utility (link)
  • Modify handleSubmit function in FacilityUsers component to use request utility instead of dispatch function to delete a user, using routes.deleteUser object to define the API endpoint and the types, and passing username as a pathParams property to the request utility (link)
  • Modify linkFacilitySubmit function in FacilityUsers component to use request utility instead of dispatch function to link a facility to a user, using routes.addUserFacility object to define the API endpoint and the types, and passing facility as a body and username as a pathParams property to the request utility (link)
  • Remove isLoading variable from the condition to render the manageUsers component, and remove loading prop from the CountCard component, as they are no longer needed for handling the loading state of the data fetching (link,link)
  • Add types for IFacilityNotificationRequest, IFacilityNotificationResponse, DeleteModel, and IUserFacilityRequest to ./src/Components/Facility/models.tsx (link)
  • Add imports of CapacityModal, DoctorModal, PatientStatsModel, IFacilityNotificationRequest, IFacilityNotificationResponse, IUserFacilityRequest, and DeleteModel to ./src/Redux/api.tsx (link)
  • Add TRes property to routes.getUser, routes.deleteUser, routes.getFacilityUsers, routes.deleteFacility, routes.getCapacity, routes.listDoctor, and routes.getTriage objects to define the type for the response for the API endpoints to get a user by username, to delete a user by username, to get the users for a facility, to delete a facility by id, to get the capacity for a facility, to get the doctor for a facility, and to get the triage for a facility, respectively (link,link,link,link,link,link,link)
  • Add TBody and TRes properties to routes.addUserFacility, routes.deleteUserFacility, and routes.sendNotificationMessages objects to define the types for the request and the response for the API endpoints to link a facility to a user, to unlink a facility from a user, and to send notification messages to a facility, respectively (link,link,link)
  • Modify path property of routes.deleteUser and routes.deleteFacility objects to include the {username} and {id} parameters as part of the API endpoint path, respectively (link,link)

@sriharsh05 sriharsh05 requested a review from a team November 9, 2023 12:30
@sriharsh05 sriharsh05 requested a review from a team as a code owner November 9, 2023 12:30
@sriharsh05 sriharsh05 requested a review from bodhish November 9, 2023 12:30
Copy link

vercel bot commented Nov 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
care-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 28, 2023 1:41pm

Copy link

netlify bot commented Nov 9, 2023

Deploy Preview for care-egov-staging ready!

Name Link
🔨 Latest commit 521bdc6
🔍 Latest deploy log https://app.netlify.com/sites/care-egov-staging/deploys/6565edc6a7c26200087de341
😎 Deploy Preview https://deploy-preview-6575--care-egov-staging.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

src/Components/Facility/models.tsx Outdated Show resolved Hide resolved
src/Redux/api.tsx Outdated Show resolved Hide resolved
src/Redux/api.tsx Outdated Show resolved Hide resolved
src/Redux/api.tsx Outdated Show resolved Hide resolved
src/Components/Facility/FacilityHome.tsx Outdated Show resolved Hide resolved
src/Components/Facility/FacilityHome.tsx Outdated Show resolved Hide resolved
src/Components/Facility/FacilityHome.tsx Outdated Show resolved Hide resolved
src/Components/Facility/FacilityUsers.tsx Outdated Show resolved Hide resolved
src/Components/Facility/FacilityUsers.tsx Outdated Show resolved Hide resolved
src/Components/Facility/FacilityUsers.tsx Outdated Show resolved Hide resolved
@sriharsh05
Copy link
Contributor Author

@rithviknishad
Please review the changes.

Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@nihal467
Copy link
Member

@sriharsh05 fix the cypress, its failing

Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the above,

src/Components/Facility/FacilityBedCapacity.tsx Outdated Show resolved Hide resolved
src/Components/Facility/FacilityDoctorList.tsx Outdated Show resolved Hide resolved
src/Components/Facility/FacilityDoctorList.tsx Outdated Show resolved Hide resolved
src/Components/Facility/FacilityDoctorList.tsx Outdated Show resolved Hide resolved
@sriharsh05
Copy link
Contributor Author

@rithviknishad
I have made the requested changes also fixed the bug which @nihal467 pointed out.

@nihal467
Copy link
Member

nihal467 commented Nov 21, 2023

@sriharsh05 @rithviknishad
image

the doctor capacity total count is not working properly

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Nov 22, 2023
Copy link

👋 Hi, @sriharsh05,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@sriharsh05
Copy link
Contributor Author

@rithviknishad Please review the PR.

@rithviknishad rithviknishad added needs testing and removed test failed merge conflict pull requests with merge conflict labels Nov 25, 2023
@nihal467
Copy link
Member

LGTM

@khavinshankar khavinshankar merged commit 4da37ba into ohcnetwork:develop Nov 29, 2023
33 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants